package com.kennedy.atoupdate.service;

import com.kennedy.atoupdate.beans.GroupInfo;
import com.kennedy.atoupdate.beans.VersionGroup;
import com.kennedy.atoupdate.mapper.VersionGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by tao.zeng on 2017/8/18.
 */
@Service
public class VersionGroupService {
    @Autowired
    private VersionGroupMapper versionGroupMapper;

    public void deleteByVersionId(Long versionInfoId) {
        Example example = new Example(VersionGroup.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("versionInfoId", versionInfoId);
        versionGroupMapper.deleteByExample(example);
    }

    public void batchAdd(List<VersionGroup> versionGroups) {
        versionGroupMapper.insertList(versionGroups);
    }

    public boolean checkIsPushGroup(Long versionInfoId, Long groupInfoId) {

        VersionGroup versionGroup = new VersionGroup();
        versionGroup.setVersionInfoId(versionInfoId);
        versionGroup.setGroupInfoId(groupInfoId);
        if (null == versionGroupMapper.selectOne(versionGroup)) {
            return false;
        } else {
            return true;
        }
    }

    public List<VersionGroup> getListByVersionInfoId(Long versionInfoId) {
        Example example = new Example(VersionGroup.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("versionInfoId", versionInfoId);
        return versionGroupMapper.selectByExample(example);
    }
}
